package pl.edu.agh.iosr.gamblingzone.mainpanel.action;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import pl.edu.agh.iosr.gamblingzone.dao.DisciplineDAO;
import pl.edu.agh.iosr.gamblingzone.dao.ejb.DisciplineDAOBean;
import pl.edu.agh.iosr.gamblingzone.model.Discipline;
import pl.edu.agh.iosr.gamblingzone.model.Group;

@Stateless
@Name("eventtablebean")
//@Scope(ScopeType.SESSION)

public class EventDataTableAction implements EventDataTable {
	@PersistenceContext
	protected EntityManager entityManager;
	
	//@Out
	private List<EventRow> events = new ArrayList<EventRow>();

	private DisciplineDAO disciplineDAO;
	private List<Discipline> allDisciplines;

	private void setupDAO() {
        if (disciplineDAO == null) {
                disciplineDAO = new DisciplineDAOBean();
                ((DisciplineDAOBean) disciplineDAO).setEntityManager(entityManager);
        }
	}

	private List<Discipline> getAllDisciplines() {
        setupDAO();
        allDisciplines = disciplineDAO.findAll();
        return allDisciplines;
	}

	//@Create
	private void createTable() {
		for(int i=0;i<10;i++) {
			EventRow er = new EventRowAction();
			er.setName("event "+i);
			er.setOdds1("0.3");
			er.setOdds2("0.4");
			er.setDraw("0.3");
			er.setClosingdate("00-00-00");
			events.add(er);
		}
	}
	
	@Out
	public List<EventRow> getEvents() {
		createTable();
		return this.events;
	}

	public void setEvents(List<EventRow> events) {
		this.events = events;
	}
}
